package com.zy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zy.entity.Apply;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface ApplyMapper extends BaseMapper<Apply> {

    Integer addApply(Apply apply);

    @Select("SELECT appid,type,uid,date,duration,place,reason,department_id,apply_state,apply_start_time,apply_end_time,title,`name`,path,post FROM (SELECT id uid,`name`,path,post FROM `user` WHERE id=#{uid}) u,(SELECT id appid,user_id,type,date,duration,place,reason,department_id,apply_state,apply_start_time,apply_end_time,title FROM apply WHERE apply_state=0 OR apply_state=1) a WHERE u.uid=a.user_id")
    List<Map> getApplyList(Integer uid);

    @Select("SELECT appid,type,uid,date,duration,place,reason,department_id,apply_state,apply_start_time,apply_end_time,title,`name`,path,post FROM (SELECT id uid,`name`,path,post FROM `user` WHERE id=#{uid}) u,(SELECT id appid,user_id,type,date,duration,place,reason,department_id,apply_state,apply_start_time,apply_end_time,title FROM apply WHERE apply_state=2 OR apply_state=-1) a WHERE u.uid=a.user_id")
    List<Map> getApplyListAnd(Integer uid);
}
